package com.niit.syy.unit_priceByhouse_type;

import com.niit.syy.util.DataConvUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Unit_priceByhouse_typeMapper extends Mapper<LongWritable, Text, Text, Text> {
    private Text outk = new Text();
    private Text outv = new Text();

    /**
     * map 3 15
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String lineData = value.toString();
        String[] datas = lineData.split(",");
        if (datas.length >= 15) {
            String unitPriceStr = datas[15]; //房屋单价
            double unitPrice = DataConvUtils.strToInt(unitPriceStr, 0);
            if (unitPrice > 15000) {
                outk.set("15001元/㎡");
            } else if (unitPrice >= 12001 && unitPrice <= 15000) {
                outk.set("12001-15000元/㎡");
            } else if (unitPrice >= 9001 && unitPrice <= 12000) {
                outk.set("9001-12000元/㎡");
            } else if (unitPrice >= 6001 && unitPrice <= 9000) {
                outk.set("6001-9000元/㎡");
            } else if (unitPrice >= 3001 && unitPrice <= 6000) {
                outk.set("3001-6000元/㎡");
            } else if (unitPrice >= 0 && unitPrice <= 3000) {
                outk.set("0-3000元/㎡");
            }

            outv.set(datas[3]);// 房源户型
            context.write(outk, outv);
        }
    }
}
